﻿using System;
using System.Collections.Generic;
using System.ComponentModel.DataAnnotations;
using System.Linq;
using System.Web;

namespace Gfw.Web.Common
{
    public static class AttributeHelper
    {
        public static string GetDisplaynName(this int enumSort, Type enumType)
        {
            try
            {
                var enumName = Enum.GetName(enumType, enumSort);
                var attribute = enumType.GetField(enumName).GetCustomAttributes(false).Where(c => c.GetType() == typeof(System.ComponentModel.DataAnnotations.DisplayAttribute)).FirstOrDefault();
                if (attribute != null)
                {
                    return (attribute as DisplayAttribute).Name;
                }

                return enumName;
            }
            catch(Exception exp)
            {
                return "未知类型";
            }
        }
    }
}